<template>
    <div>
        <h1>正在跳转中。。。。</h1>
        <h2>获取到的微博code是：{{weibo_code}}</h2>
    </div>
</template>
<script>
import axios from "axios"
export default {
    name:"weibo_callback",
    data(){
        return{
            weibo_code:"",
        }
    },methods:{
        get_weibo_code(){
            var code=this.$route.query.code
            this.weibo_code=code
        },
        send_code(){
            axios({
                url:"http://127.0.0.1:8000/weibo_code/",
                method:"GET",
                params:{"code":this.weibo_code},
                headers:{
                    "Authortions":"JWT " +sessionStorage.getItem("jwt_token")
                }
            }).then(res=>{
                console.log(res.data)
                if(res.data.code===200){
                    sessionStorage.setItem("jwt_token",res.data.token)
                    window.location.href = "https://www.baidu.com"
                }else if(res.data.code==4004){
                    //第一次登录，需要绑定信息
                    sessionStorage.setItem("u_id",res.data.uid)
                    this.$router.push({path:"/simuser"})
                }else{
                    alert("微博登录失败，请重试")
                }
            })
        }

    },mounted(){
        this.get_weibo_code()
        this.send_code()
    }
}
</script>
<style>

</style>